package com.scrawler.util;



import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;

import org.springframework.stereotype.Service;

import com.scrawler.vo.News;




/**  
 * @Description: 描述
 * @author kuntang    
 * @version 1.0  
 * @created 2012-11-14 上午11:50:46 
 * Copyright (c) 2012 sohu,Inc. All Rights Reserved.
 */

@Service
public class DataLib {
	/** 视觉信息数据(新闻), key: channelId, value: map<nid,score>*/
	private static Map<Integer,ConcurrentMap<Integer,Float>> pageViewNewsData = 
			new HashMap<Integer,ConcurrentMap<Integer,Float>>();
	/** 百度热词数据,key: channelId,value: map<keywords,score>*/
	private static Map<Integer,ConcurrentMap<String,Float>> baiduHotwordsData = 
			new HashMap<Integer,ConcurrentMap<String,Float>>();
	/** 推荐中间数据*/
	private static Map<Integer,ConcurrentMap<Integer,News>> newsInfoData = 
			new HashMap<Integer,ConcurrentMap<Integer,News>>();
	
	static{

		
	}
	
	public void addPageViewItem(int channelId,int nid,float score){
		pageViewNewsData.get(channelId).put(nid, score);
	}
	
	public boolean pageViewContainsKey(int channelId,int nid){
		return pageViewNewsData.get(channelId).containsKey(nid);
	}
	
	public Map<Integer,Float> getPageViewScoreByChannelId(int channelId){
		return Collections.unmodifiableMap(pageViewNewsData.get(channelId));
	}
	

	public void addBaiduHotwordAllItem(int channelId,Map<String,Float> keyWords){
		baiduHotwordsData.get(channelId).putAll(keyWords);
	}
	
	
	
	public Map<String,Float> getBaiduHotWordsByChannelId(int channelId){
		return Collections.unmodifiableMap(baiduHotwordsData.get(channelId));
	}
	
	/** 对保存的新闻内容做操作*/
	public void addAllNewsInfo(int channelId,Map<Integer,News> newss){
		newsInfoData.get(channelId).putAll(newss);
	}
	

	public void clearPreRoundData(int channelId){
		pageViewNewsData.get(channelId).clear();
		// CBA频道不清理
		baiduHotwordsData.get(channelId).clear();
		newsInfoData.get(channelId).clear();
	}
	
	
	
	/**
	 * @Description:
	 * @Date: 2012-11-14
	 * @param: @param args
	 * @return: void
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
